package customer.zspt.cn.customer.components.chat.chatMore.ChildPager;

import android.app.Activity;
import android.view.View;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import customer.zspt.cn.customer.R;
import customer.zspt.cn.customer.components.chat.chatMore.ChatMoreBasePager;
import customer.zspt.cn.customer.Widget.ChatMoreItem;

/**
 * Created by Administrator on 2018/7/22 0022.
 */

public class ChatMoreChildPager extends ChatMoreBasePager {

    private List<Map<String,Object>> resLS = new ArrayList<>();
    private View view;
    private LinearLayout top_ll;
    private LinearLayout bottom_ll;
    public ChatMoreChildPager(Activity activity,List<Map<String,Object>> res){
        super(activity);
        this.resLS = res;
        addItemView();
    }
    @Override
    public View initView() {
        view = View.inflate(mActivity, R.layout.chatmorevpitem,null);
        top_ll = view.findViewById(R.id.top_ll);
        bottom_ll = view.findViewById(R.id.bottom_ll);
        return view;
    }

    //添加控件
    private void addItemView() {
        for(int i = 0; i < resLS.size();i++)
        {
            LinearLayout.LayoutParams params =
                    new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1);
            ChatMoreItem item = new ChatMoreItem(mActivity);
            item.setTitle((String)resLS.get(i).get("title"));
            item.setIcon((int)resLS.get(i).get("icon"));
            item.setLayoutParams(params);
            item.setOnClickListener(clickListener);
            if(i<4)
            {
                top_ll.addView(item);
            }
            else{
                bottom_ll.addView(item);
            }
        }
        LinearLayout.LayoutParams params =
                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1);
        if(resLS.size()<4)
        {
            for(int i=0;i<4-resLS.size();i++)
            {
                ChatMoreItem item = new ChatMoreItem(mActivity);
                item.setTitle("");
                item.setLayoutParams(params);
                top_ll.addView(item);
            }
        }
        if(resLS.size()>=4&&resLS.size()<8)
        {
            for(int i=0;i<8-resLS.size();i++)
            {
                ChatMoreItem item = new ChatMoreItem(mActivity);
                item.setTitle("");
                item.setLayoutParams(params);
                bottom_ll.addView(item);
            }
        }
    }
    public View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ChatMoreItem item = (ChatMoreItem) v;
            if(mLintener!=null)
            {
                mLintener.getTitle(item.getTitle());
            }
        }
    };


    GetTileLintener mLintener;
    public void setGetTitleLintener(GetTileLintener mLintener){
        this.mLintener = mLintener;
    }
    public interface GetTileLintener{
        void getTitle(String title);
    }

}
